#/bin/bash

#### dependencies:
# 1) feh --> background
# 2) alsamix --> audio infos
# 3) acpitool --> battery infos
# 4) ifconfig --> networkinfos

#### infos:
# 1) updates all 0.5 seconds 
#		--> volume and battery state in the statusbar updates only all 0.5 seconds --> easy editable
#		--> update time is not in syc with the system time --> seconds display may look laggy
# 2) network is looking for the strings 'eth0' and 'wlan0' --> easy editable

#feh --bg-scale --randomize ./.wall/

while true
do
   battery=$(acpi | cut -d"," -f2 | cut -d" " -f2)
   usd=$(df /dev/root -BG | tail -1 | awk '{print $3}')
   avb=$(df /dev/root -BG | tail -1 | awk '{print $4}')
   usdh=$(df /dev/home -BG | tail -1 | awk '{print $3}')
   avbh=$(df /dev/home -BG | tail -1 | awk '{print $4}')
   usdm=$(free -m | egrep "Mem" | awk '{print$3}')
   avbm=$(free -m | egrep "Mem" | awk '{print$2}')
   usds=$(free -m | egrep "Swap" | awk '{print$3}')
   avbs=$(free -m | egrep "Swap" | awk '{print$2}')
   
   ip=$(ifconfig wlp2s0| grep inet|head -1|awk '{print $2}')
   ip="ip:${ip}"
   vol=$(amixer get Master | egrep "Mono:"| awk '{print $4}' | cut -d"]" -f1 | cut -d"[" -f2)
   vol="${vol}"
   mute=$(amixer get Master | egrep "^  Front Left"| cut -d"[" -f 4 | cut -d"]" -f 1)
   tmp="eth0:"
   if [ "$ip" = "$tmp" ]
	then
        ip=$(ifconfig wlan0| grep "inet A"|cut -d: -f2 | cut -d" " -f 1)
	ip="wlan0:${ip}"
   fi
   tmp="off"
   if [ "$mute" = "$tmp" ]
	then
	vol="mute"
   fi
   xsetroot -name "/:$usd/$avb  /home:$usdh/$avbh  mem:$usdm/$avbm  swap:$usds/$avbs  vol:$vol  $(date +"%A %y.%m.%d %H:%M:%S")"
   sleep 0.5    # Update time
done &
